﻿using Abp.Extensions;
using Abp.Runtime.Session;
using Abp.Timing.Timezone;
using AppFramework.Auditing.Dto;
using AppFramework.Auditing.Exporting;
using AppFramework.DataExporting.Excel.NPOI;
using AppFramework.DinosaursParkMes.CodingRuleModel;
using AppFramework.Dto;
using AppFramework.Storage;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppFramework.DinosaursParkMes.WorkOrder.CodingPush
{
    public class CodingPushExcel : NpoiExcelExporterBase, ICodingPushExcel
    {
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;
        public CodingPushExcel(ITempFileCacheManager tempFileCacheManager, ITimeZoneConverter timeZoneConverter, IAbpSession abpSession) : base(tempFileCacheManager)
        {
            _timeZoneConverter = timeZoneConverter;
            _abpSession = abpSession;
        }
        /// <summary>
        /// 设置导出Excel的内容
        /// </summary>
        /// <param name="auditLogListDtos"></param>
        /// <returns></returns>
        [HttpGet,Route("ExportToFile")]
        public FileDto ExportToFile(List<Codingrules> auditLogListDtos)
        {
            return CreateExcelPackage("CodingPush.xlsx", excelPackage =>
            {
                var sheet = excelPackage.CreateSheet(L("AuditLogs"));
                //添加头
                AddHeader(
                    sheet,
                    L("目标表单"),
                    L("编码名称"),
                    L("编号前戳"),
                    L("时间规则"),
                    L("生成类型"),
                    L("初始流水号"),
                    L("流水号长度"),
                    L("步长"),
                    L("编号预览"),
                    L("编码生成规则")
                    );
                AddObjects(
                    sheet,
                    auditLogListDtos,
                        _ => _.TargetForm,
                        _ => _.CodingName,
                        _ => _.CodingProd,
                        _ => _.TimeRule,
                        _ => _.GenerateType,
                        _ => _.InitialNumber,
                        _ => _.InitialLong,
                        _ => _.StepSize,
                        _ => _.CodingPreview,
                        _ => _.CodingGenerateRule
                    );
                for (int i = 0; i < 9; i++)
                {
                    sheet.AutoSizeColumn(i);
                }
            });
        }
    }
}
